<template>
  <div id="mapContainer">
    <!-- <object  type="text/html" style="width: 100%; height: 100%;" :data="mapUrl" ></object> -->
  </div>
</template>

<script>
import { FileServerProxy, getZjfGeomP } from "../../utils/api";
export default {
  data() {
    return {
      mapUrl: "",
    }

  },
  methods: {
    init() {
      let selectedData = JSON.parse(this.form);
      let node, type, cityCode;
      var rowGuid = "";
      cityCode = selectedData.TOWN;
      if (selectedData.WF_GUID == "{9FF1C524-B55F-4A45-83B3-6EA46CF32092}") {//建房审批
        rowGuid = selectedData.ROW_GUID;
      } else {
        rowGuid = selectedData.ROW_GUID;
      }
      if (selectedData.NODE_GUID == "{5E1AD806-7824-4196-8ADF-E231A8704FD3}" || selectedData.NODE_GUID == "{517211B4-3740-4F49-9DA4-7BC3C9A6F9EA}" || selectedData.NODE_GUID == "{67241083-CA60-43FC-B1C1-1F4A2D133184}") {//现场踏勘
        node = "takan";
        type = "edit";

      } else {
        node = "takan";
        type = "view";

      }
      if (rowGuid) {
        let ismapParam = {
          procName: "get_houseapplymsgg",
          dtParams: JSON.stringify([{ i_rowGuid: rowGuid, i_taskID: selectedData.TASK_ID }]),
          token: window.localStorage.getItem("token"),
        };
        let isMapExpro = {
          accessCode: "69db6bece3a7480592e2ec753d1e335e",
          cityCode: window.localStorage.getItem("citycode")
            ? window.localStorage.getItem("citycode")
            : "441300000000",
          params: ismapParam,
        };
        FileServerProxy(isMapExpro).then((data) => {
          if (data.data && data.data.data && JSON.parse(data.data.data).Data.length > 0) {
            var result = JSON.parse(data.data.data).Data;
            // 获取div标签
            var activity = document.querySelector('#mapContainer1');
            // 创建日期
            var ts = new Date().getTime()
              ;// 使用es6模板语法 将变量拼接到地址栏
            document.write(`<iframe style="width: 100%; height: 100%;"  src="${window.g.MapUrl + "?jieduan=" + node + "&data=" + encodeURIComponent(JSON.stringify(result)) + "&type=" + type + "&user=" + cityCode + '&time=' + ts}"frameborder="0" :key='${ts}'></iframe>`)
            // this.mapUrl = window.g.MapUrl + "?jieduan=" + node + "&data=" + encodeURIComponent(JSON.stringify(result)) + "&type=" + type + "&user=" + cityCode + '&time=' + ts;
          } else {
            this.$toast.fail('请先报存表单数据!')
          }
        });
        //   var data = [{
        //   "JDID": "" + selectedData.NODE_GUID + "",
        //   "SQBH": "" + rowGuid+ "",
        //   "FWBH": "" + selectedData.FAMILYHOUSEID + "",
        //   "APPLICANT": "" + selectedData.HOUSEAPPLICANT + "",
        //   "ADDESS": ""+selectedData.ADDRESS+""
        // }]

      } else {
        this.$toast.fail('关联编号为空!')
      }

    },
    async mapDWBy() {
      debugger
      let selectedData = JSON.parse(this.form);
      let cityCode;
      cityCode = selectedData.TOWN?selectedData.TOWN:selectedData.villageCode;
      let GeomP = await getZjfGeomP("YH330111000004676")
      if (GeomP.data && GeomP.data.data && GeomP.data.data[0]) {
        // 获取div标签
        let dataValue = [{ "geomP": GeomP.data.data[0] }]
        var activity = document.querySelector('#mapContainer1');
        // 创建日期
        var ts = new Date().getTime()
          ;// 使用es6模板语法 将变量拼接到地址栏
        document.write(`<iframe style="width: 100%; height: 100%;"  src="${window.g.MapUrl + "?data=" + encodeURIComponent(JSON.stringify(dataValue)) + "&user=" + cityCode + '&time=' + ts}"frameborder="0" :key='${ts}'></iframe>`)
        //   this.$router.push({
        //   path: '/mapContainer',
        //   query: {
        //     data: JSON.stringify(this.$route.query.data),
        //     zjfhc:"1"
        //   }
        // })
      }
      let dataValue = [{ "geomP": this.rowData.geomP }]
    },
  },
  mounted() {
    //  进入事件
    // this.$router.go(0)
    this.form = JSON.parse(this.$route.query.data);
    if (JSON.parse(this.$route.query.zjfhc) == "1") {
      this.mapDWBy();
    } else {
      this.init()
    }

    if (ZWJSBridge) {
      ZWJSBridge.setTitle({
        "title": "地图"
      }).then(res => {
      }).catch(err => {
      })
    }
  }
}
</script>

<style lang="scss" scoped>
#mapContainer {
  width: 100vw;
  height: 100vh;
  overflow: auto;
  background: #ffffff;
}
</style>
